package com.alex.monitor.core.properties;

import cn.hutool.http.Method;
import com.alex.monitor.core.alarm.MonitorAlarm;
import com.alex.monitor.core.enums.AlarmType;
import com.google.common.collect.Lists;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 监控配置类
 *
 * @author Alex.Liu
 * @date: 2025-02-16 14:13
 * @since 1.0.0
 */
@Getter
@Setter
@ConfigurationProperties(prefix = "alex.monitor")
public class AlexMonitorProperties implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 发送器类型列表,默认使用日志发送器
     */
    private List<AlarmType> alarmTypes = Lists.newArrayList(AlarmType.LOG);

    /**
     * 自定义发送器列表
     */
    private List<Class<MonitorAlarm>> alarms = Lists.newArrayList();

    /**
     * 邮箱相关配置
     */
    private EmailConfig email;

    /**
     * HTTP通知地址相关配置
     */
    private HttpConfig http;

    /**
     * 邮箱配置内部类
     */
    @Getter
    @Setter
    public static final class EmailConfig implements Serializable {

        /**
         * SMTP服务器主机地址
         * 例如: smtp.example.com
         */
        private String host;

        /**
         * SMTP服务器端口
         */
        private Integer port;

        /**
         * SMTP服务器登录用户名
         */
        private String username;

        /**
         * SMTP服务器登录密码
         */
        private String password;

        /**
         * SMTP服务器使用的协议
         */
        private String protocol = "smtp";

        /**
         * 默认的MimeMessage编码
         */
        private Charset defaultEncoding = StandardCharsets.UTF_8;

        /**
         * 额外的JavaMail会话属性
         */
        private Map<String, String> properties = new HashMap<>();

        /**
         * 邮件接收方列表
         */
        private List<String> to;
    }

    /**
     * HTTP通知配置内部类
     */
    @Getter
    @Setter
    public static final class HttpConfig implements Serializable {

        private static final long serialVersionUID = 1L;

        /**
         * 通知地址URL
         */
        private String url;

        /**
         * HTTP请求方法
         */
        private Method method = Method.POST;

        /**
         * 请求内容类型
         */
        private String contentType = "application/json";

        /**
         * 默认字符编码
         */
        private Charset defaultEncoding = StandardCharsets.UTF_8;

        /**
         * 请求头
         */
        private Map<String, String> headers = new HashMap<>();
    }
}